package com.capgemini.diabeo.manager;


import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

import com.googlecode.androidannotations.annotations.EBean;
import com.googlecode.androidannotations.api.Scope;

import android.os.Handler;


@EBean(scope = Scope.Singleton)
public class SearchManager {
	
	private List<ChangeObserver> observers = new CopyOnWriteArrayList<ChangeObserver>();
	private Handler mHandler;
	
	
	public SearchManager() {
		super();
		mHandler = new Handler();
	}
	
	public void registerChangeObserver(ChangeObserver observer) {
		synchronized (observers) {
			observers.add(observer);
		}
	}
	
	
	public void notifyChange(final String text) {
		
		synchronized (observers) {
			for (final ChangeObserver observer : observers) {
				mHandler.post(new Runnable() {
					@Override
					public void run() {
						observer.onChange(text);						
					}
				});
			}
		}
	}
	
	

}
